"""


"""
from django.contrib.auth.models import Group
from rest_framework import serializers

from users.models import User


class AdminManageSerializer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = "__all__"

    def create(self, validated_data):
        instance = super().create(validated_data)
        instance.set_password(validated_data.get("password"))
        instance.is_superuser = True
        instance.is_staff = True
        instance.save()

        return instance

    def update(self, instance, validated_data):
        instance = super().update(instance, validated_data)
        instance.set_password(validated_data.get("password"))
        instance.save()
        return instance


class GroupSimpleSerializer(serializers.ModelSerializer):
    class Meta:
        model = Group
        fields = ("id", "name")

